package edu.mobbuzz.web.facade;

import java.util.ArrayList;
import java.util.List;

import edu.mobbuzz.daf.bean.Logs;
import edu.mobbuzz.daf.bean.Rss;
import edu.mobbuzz.daf.bean.Subscriber;
import edu.mobbuzz.daf.dao.ILogsDao;
import edu.mobbuzz.daf.dao.IRssDao;
import edu.mobbuzz.daf.dao.ISubscriberDao;
import edu.mobbuzz.util.DBUtility;

public class SchedularFacade extends BaseFacade{
	private ISubscriberDao subscriberDao;
	private ILogsDao logsDao;
	private IRssDao rssDao;
	
	public IRssDao getRssDao() {
		if(rssDao==null)
			rssDao = (IRssDao)getFactory().getBean("rssDao");
		return rssDao;
	}
	
	public ISubscriberDao getSubscriberDao() {
		if(subscriberDao==null)
			subscriberDao=(ISubscriberDao)getFactory().getBean("subscriberDao");
		return subscriberDao;
	}

	
	public ILogsDao getLogsDao() {
		if(logsDao==null)
			logsDao = (ILogsDao)getFactory().getBean("logsDao");
		return logsDao;
	}
	
	
	/*public Subscriber getSubscriberByUsernameAndUrl(String username, String url){
		Subscriber subscriber = (Subscriber)getSubscriberDao().queryForBaseBean("username='"+username+"' AND url='"+url+"'");	
		return subscriber;
		
	}
	*/
	public List<Subscriber> getSubscriberList(String where, String order){
		List<Subscriber> subscriberList = getSubscriberDao().queryForList(where, order);
		
		if(subscriberList==null){
			subscriberList = new ArrayList<Subscriber>();
			return subscriberList;			
		}else{
			return subscriberList;
		}		
	}
	
	/*public Subscriber checkSubscriberExist(String username, String url){
		Subscriber _subscriber = (Subscriber) getSubscriberDao().queryForBaseBean("username='"+username+"' AND url='"+url+"' ");
		return _subscriber;
	}
	*/
	public boolean addLogs(Logs logs){		
		try{
			getLogsDao().insert(logs);
			return true;
		}catch (Exception e) {
			return false;
		}
		
	}
	
	public boolean updateLogs(Logs logs){		
		try{
			getLogsDao().update(logs);
			return true;
		}catch (Exception e) {
			return false;
		}
		
	}
	
	public List<Logs> getLogsList(String where, String order){		
		List<Logs> logsList = new ArrayList<Logs>();
		logsList = getLogsDao().queryForList(where, order);
		
		return logsList;
		
	}
	
	public Logs getLogs(String where){		
		Logs _logs = (Logs)getLogsDao().queryForBaseBean(where);
		return _logs;
		
	}
	
	public List<Rss> getRssList(String where, String order){
		List<Rss> rssList = rssList = new ArrayList<Rss>();
		rssList = getRssDao().queryForList(where, order);
		return rssList;
	}
	
	/*public boolean addRss(String url){
		Rss _rss = new Rss();
		_rss.setUrl(url);
		
		try{
			getRssDao().insert(_rss);
			return true;
		}catch (Exception e) {
			return false;
		}
		
	}*/
	
	/*public boolean checkRSSExist(String rss){
		Rss _rss = (Rss)getRssDao().findByPrimaryKey(rss);
		if(_rss!=null){
			return true;
		}else{
			return false;
		}
		
	}*/
}
